package com.yhd.tomcat.handler.process;

import com.yhd.tomcat.Bootstrap;
import com.yhd.tomcat.handler.Handler;
import com.yhd.tomcat.listener.EventListener;
import com.yhd.tomcat.publish.PublishAdapter;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author yhd
 * @email yinhuidong1@xiaomi.com
 * @description TODO
 * @since 2021/6/10 下午4:26
 */
public class ProcessHandler extends Handler {

    private static volatile ProcessHandler processHandler;

    private ProcessHandler() {
    }

    public static ProcessHandler getSingleton(){
        if (processHandler==null){
            synchronized (Bootstrap.class){
                if (processHandler==null){
                    processHandler=new ProcessHandler();
                }
            }
        }
        return processHandler;
    }

    public void process(ServerSocket serverSocket){
        try {

            for (;;) {
                Socket socket = serverSocket.accept();
                //待验证,请求来了之后放入到队列中
                EVENTQUEUE.put(socket);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
